package com.ykdl.net.response;

import com.ykdl.member.KidApp;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.response.HttpResponse;
import android.widget.Toast;


/**
 * 该类执行与UI线程中，刷新UI
 * @author yuanwenfei
 * @param <T>
 */

public abstract class AndroidHttpResponse<T> extends HttpResponse<T> {
	
	@Override
	protected void cancelInUIThread(final ITag<T> tag) {
		KidApp.getInstance().runOnUIThread(new Runnable() {

			@Override
			public void run() {
				AndroidHttpResponse.super.cancelInUIThread(tag);
			}
			
		});
	}
	@Override
	protected void completeInUIThread(final ITag<T> tag, final DataState ds) {
		KidApp.getInstance().runOnUIThread(new Runnable() {

			@Override
			public void run() {
				AndroidHttpResponse.super.completeInUIThread(tag, ds);
			}
			
		});
		
	}
	@Override
	protected void failInUIThread(final ITag<T> tag, final DataParseError error) {
		KidApp.getInstance().runOnUIThread(new Runnable() {
			@Override
			public void run() {
				if(!tag.refreshError(error)) {
					//toast error;
					Toast.makeText(KidApp.getInstance().getApplicationContext(), error.getErrMsg(), Toast.LENGTH_SHORT).show();
				}
			}
			
		});
		
	}
	
}
